using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using Pine.Core;
using Pine.SourceParser.Tree;
using PPT=Pine.SourceParser.Tree;

namespace Pine.CodeGen
{
	public static class TypeConstantCodeGenerator
	{
		private static IDictionary<PPT.TypeConstantType, FieldInfo> types = new Dictionary<PPT.TypeConstantType, FieldInfo>();
		
		static TypeConstantCodeGenerator() {
			types[PPT.TypeConstantType.Number] = typeof(PineType).GetField("NumberType");
		}
		
		public static void GenerateBytecode(Context ctx, Expression expr, LocalBuilder lb) {
			TypeConstantType type = ((TypeConstant) expr).type;
			ctx.il.Emit(OpCodes.Ldsfld, types[type]);
			ctx.il.Emit(OpCodes.Stloc, lb);
		}
	}
}

